001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Nov 27, 2002
005 * Time: 3:57:05 PM
006 */
007
008 package EVolve.visualization.XYViz.ValRefViz;
009
010 import EVolve.visualization.XYViz.XYVisualization;
011 import EVolve.visualization.XYViz.ValRefViz.HotSpotViz.PredictionViz;
012 import EVolve.visualization.*;
013 import EVolve.visualization.VizFactory.VisualizationFactory;
014 import EVolve.util.predefinedutils.VizInfo;
015 import EVolve.Scene;
016 import EVolve.exceptions.VizInfoCreateException;
017 import EVolve.exceptions.NoDataPlotException;
018 import EVolve.data.ElementDefinition;
019 import EVolve.data.DataFilter;
020 import EVolve.data.Entity;
021 import EVolve.data.Selection;
022
023 import java.util.*;
024
025
026 public abstract class ValueReferenceVisualization extends XYVisualization{
027 protected ValueDimension xAxis;
028 protected ReferenceDimension yAxis;
029 protected ReferenceDimension zAxis;
030
031 public Dimension[] createDimension() {
032 Dimension [] returnDimension = new Dimension[2];
033
034 xAxis = new ValueDimension();
035 yAxis = new ReferenceDimension();
036 zAxis = null;
037
038 returnDimension[0] = xAxis;
039 returnDimension[1] = yAxis;
040
041 return returnDimension;
042 }
043
044 public ReferenceDimension getLinkableDimension(int dim) {
045 if (dim!=1) return null;
046 return (ReferenceDimension)dimension[dim];
047 }
048
049 public void sort() {
050 try {
051 String comparatorName = "";
052 try {
053 comparatorName = yAxis.getSelectedComparatorName();
054 } catch (IndexOutOfBoundsException e) {
055 // this exception happens when user click fresh button before visulize the topmost viz
056 return;
057 }
058 int beforeLink = yAxis.getEntityNumberBeforeLink();
059 Selection activeSelection = Scene.getFilter().getActiveSelection();
060 long start = ((activeSelection == null)) ? 0 : activeSelection.getStartTime();
061 if (normalOrientation) {
062 canvas.setName(timeHeader() + xAxis.getName() + " (" +
063 ((interval == -1) ? ""+xMax+"" : ((""+start +" - ")) + (xMax > start ? xMax : start+xMax)) +
064 (interval == -1 ? "" : (",interval " + String.valueOf(interval))) +")",
065 yAxis.getName() + " (" + ((beforeLink == -1) ? "" : (""+beforeLink+" / ")) +
066 yAxis.getEntityNumber() + ", " + comparatorName +")");
067 canvas.setImage(image.getSortedImage(null, yAxis).getImage());
068 }
069 else {
070 canvas.setName(yAxis.getName() + " (" + ((beforeLink == -1) ? "" : (""+beforeLink+" / ")) +
071 yAxis.getEntityNumber() + ", " + comparatorName + ")",
072 timeHeader() + xAxis.getName() + " (" +
073 ((interval == -1) ? ""+xMax+"" : ((""+start +" - ")) + (xMax > start ? xMax : start+xMax))
074 + ")");
075 canvas.setImage(image.getSortedImage(yAxis, null).getImage());
076 }
077 if ((phaseDetector!=null)&&(phaseDetectorEnabled)) {
078 if (normalOrientation)
079 phaseDetector.drawPhase(canvas);//, yAxis.getEntityNumber());
080 else
081 phaseDetector.drawPhase(canvas);//, xAxis.getEntityNumber());
082 } else {
083 canvas.setPhases(null);
084 }
085 canvas.repaint();
086 enableBrowseSourceMenu();
087 } catch (NoDataPlotException e) {
088 Scene.showErrorMessage(e.getMessage());
089 }
090 }
091
092 public HashMap getCurrentConfigure() {
093 try {
094 HashMap configure = super.getCurrentConfigure();
095
096 VizInfo vizInfo = new VizInfo();
097 vizInfo.setFactory((VisualizationFactory)configure.get("Factory"));
098 vizInfo.setSubject((ElementDefinition)configure.get("Subject"));
099
100 String[] dimensionDefs = new String[3];
101 dimensionDefs[0] = xAxis.getName() ;
102 dimensionDefs[1] = yAxis.getName() ;
103 dimensionDefs[2] = (zAxis == null) ? ";not using" : zAxis.getName() ;
104 configure.put("Dimension",vizInfo.createDimension(dimensionDefs));
105 if (this instanceof PredictionViz)
106 configure.put("Predictor",((PredictionViz)this).getPredictor());
107 else
108 configure.put("Predictor",null);
109 vizInfo.createInterval(new Integer(interval).toString());
110
111 return configure;
112 } catch (VizInfoCreateException e) {
113 Scene.showErrorMessage(e.getMessage());
114 }
115 return null;
116 }
117
118 protected void updateConfiguration() {
119 canvas.setName(xAxis.getName(), yAxis.getName());
120 super.updateConfiguration();
121 }
122
123 /**
124 * Mouse moved.
125 *
126 * @param x position on X-axis
127 * @param y position on Y-axis
128 */
129 protected void mouseMove(int x, int y) {
130 int X = canvas.getImageX(x);
131 int Y = canvas.getImageY(y);
132 String time = xAxis.getName();
133
134 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) {
135 if (normalOrientation) {
136 if (shift_pressed && (image.getSortedColor(null,yAxis,X,Y)==null))
137 Scene.setStatus(" ");
138 else {
139 Entity entity = yAxis.getEntity(Y);
140 time = ((interval == -1)||(X>=timeMap.size())||(X<0)) ? "" : time + ":" + ((long[])timeMap.get(X))[0];
141 Scene.setStatus(entity == null ? " " : entity.getName()+" "+time);
142 }
143 } else {
144 if (shift_pressed && (image.getSortedColor(yAxis,null,X,Y)==null))
145 Scene.setStatus(" ");
146 else {
147 Entity entity = yAxis.getEntity(X);
148 time = ((interval == -1)||(Y>=timeMap.size())||(Y<0)) ? "" : time + ":" + ((long[])timeMap.get(Y))[0];
149 Scene.setStatus(entity == null ? " " : entity.getName()+" "+time);
150 }
151 }
152 } else {
153 Scene.setStatus(" ");
154 }
155 }
156
157 protected void changeOrientation() {
158 super.changeOrientation();
159 sort();
160 }
161
162 private String timeHeader() {
163 DataFilter dataFilter = xAxis.getDataFilter();
164 String[] property = dataFilter.getProperty();
165 for (int i=0; i< property.length; i++) {
166 if (property[i].equals("time"))
167 return "Time - ";
168 }
169 return "";
170 }
171
172 protected String getEntityUnderMouse() {
173 int X = canvas.getImageX(mouseX);
174 int Y = canvas.getImageY(mouseY);
175
176 if ((Y >= 0) && (Y < yAxis.getEntityNumber())) {
177 if (normalOrientation) {
178 if ((image.getSortedColor(null,yAxis,X,Y)!=null))
179 return yAxis.getEntity(Y).getName();
180 } else {
181 if (image.getSortedColor(yAxis,null,X,Y)!=null)
182 return yAxis.getEntity(X).getName();
183 }
184 }
185
186 return null;
187 }
188
189 public Object clone(){
190 ValueReferenceVisualization o = null;
191
192 o = (ValueReferenceVisualization)super.clone();
193
194 o.xAxis =(ValueDimension)xAxis.clone();
195 o.yAxis =(ReferenceDimension) yAxis.clone();
196 o.zAxis =(zAxis == null) ? null : (ReferenceDimension)zAxis.clone();
197 //o.eventCounter = (eventCounter == null) ? null : (ArrayList) eventCounter.clone();
198 o.dimension[0] = o.xAxis;
199 o.dimension[1] = o.yAxis;
200 if (o.zAxis != null) o.dimension[2] = o.zAxis;
201 o.createMenu();
202 /*o.eventCounter = new ArrayList();
203 o.timeCounter = new ArrayList();
204 for (int i=0; i<eventCounter.size(); i++)
205 o.eventCounter.add(eventCounter.get(i));
206
207 for (int i=0; i<timeCounter.size(); i++)
208 o.timeCounter.add(timeCounter.get(i));
209 */
210
211 return o;
212 }
213 }